<template>
  <div class="micro-image-ad-box">
    <!--预览区-->
    <div class="design-preview-controller">
      <div v-if="formData.imageList.length"
           class="ad-view-box"
           :class="'ad-view-'+formData.indicator">
        <div v-if="formData.indicator ===1 || formData.indicator ===4 ">
          <img v-for="(item, index) in formData.imageList"
               :key="index"
               style="display: block"
               :src="item.url"
               alt="">
        </div>
      </div>
      <div v-else
           class="image-ad-view">
        <div class="image-ad-title">
          {{$t('shopFeature.imageAd.widthSuggest')}}
        </div>
      </div>
    </div>
    <!--编辑区-->
    <div v-show="isShowEdit"
         class="design-editor-item design-hide-class">
      <div class="design-config-editor">
        <div class="design-editor-component-title">{{$t('shopFeature.imageAd.hotArea')}}</div>
        <div class="image-ad-edit">         
          <p style="margin-top: 20px;">{{$t('shopFeature.imageAd.addPic')}}
            <span style="color:#b7b7b7;">{{$t('shopFeature.imageAd.max10Ads')}}</span>
          </p>
          <!--hot model-->
          <draggable :list="formData.imageList"
                      ghost-class="ghost"
                      handle=".ad-handle">
            <div v-for="(item,index) in formData.imageList"
                  :key="index"
                  class="ad-image-hot">
              <div class="add-ad-image"
                    @click="showHotAreaPop(index)">{{$t('shopFeature.imageAd.addHotArea')}}</div>
              <div class="add-ad-image"
                    @click="changeImg(index)">{{$t('shopFeature.tabNav.changePic')}} </div>
              <div class="ad-image-hot-box">
                <div v-show="item.activeBoxs.length"
                      class="ad-image-hot-content ad-handle">
                  <span v-for="(hotItem,hotIndex) in item.activeBoxs"
                        :key="hotIndex"
                        class="ad-hot-box-item"
                        :style="`transform: translate(${hotItem.translateX * hotScale}px,${hotItem.translateY * hotScale}px);width:${hotItem.width * hotScale}px;height:${hotItem.height * hotScale}px;`">
                    <el-dropdown trigger="click"
                                  size="small"
                                  @command="command">
                      <div class="cursor">
                        <p v-if="hotItem.type!=1 && hotItem.type!=4 ">{{ hotItem.title|| $t('shopFeature.imageAd.setRoute') }}</p>
                        <p class="hot-item-title" v-if="hotItem.type===1 || hotItem.type===4 ">{{ hotItem.type | typeNameFilter(that) }}</p>
                        <p class="hot-item-title" v-if="hotItem.type===1 || hotItem.type===4 " @click.stop="handleChangeLinkOrProd(index, hotIndex, hotItem.type)">{{ hotItem.title }}</p>
                      </div>
                      <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item v-for="(linkItem,linkIndex) in linkList"
                                          :key="linkIndex"
                                          :command="({linkItem,currentHotEditIndex:hotIndex,currentEditIndex:index})">
                          <span style="font-size: 12px;">{{ linkItem.title }}</span>
                        </el-dropdown-item>
                      </el-dropdown-menu>
                    </el-dropdown>
                    <i class="el-icon-close close-icon"
                        @click="item.activeBoxs.splice(hotIndex, 1)" />
                  </span>
                </div>
                <img class="ad-handle"
                      :src="item.url">
                <i class="el-icon-error close-icon"
                    @click="formData.imageList.splice(index, 1)" />
              </div>
            </div>
          </draggable>
          <!--选择图片框-->
          <div v-if="10 - formData.imageList.length !== 0"
               class="ad-add-image"
               @click="elxImgboxHandle">
            <!-- @click="canChooseImagesNum = 10 - formData.imageList.length;isChangeImg = false;dialogChooseImgVisible = true;" -->
            <p>
              <i class="el-icon-plus" /> {{$t('shopFeature.imageAd.addBgImg')}}
            </p>
            <p style="color: #b7b7b7;">{{$t('shopFeature.imageAd.widthSuggest')}}</p>
          </div>
        </div>
      </div>
    </div>

    <el-dialog custom-class="up-dialog"
               :close-on-click-modal="false"
               top="5vh"
               :title="$i18n.t('shopFeature.imageAd.addHotArea')"
               :visible.sync="dialogHot"
               width="550px">
      <div class="ad-hot-box">
        <div v-if="dialogHot&&formData.imageList.length">
          <img :src="formData.imageList[currentEditIndex].url"
               class="box-img">
          <div v-for="(item,index) in cacheImageActiveBox"
               :key="index"
               v-drag="{cacheImageActiveBox,index}"
               class="ad-drag">
            <el-dropdown trigger="click"
                         size="small"
                         @command="command">
              <div class="cursor">
                <p v-if="item.type!=1 && item.type!=4 ">{{ item.title|| $t('shopFeature.imageAd.setRoute') }}</p>
                <p v-if="item.type===1 || item.type===4 ">{{ item.type | typeNameFilter(that) }}</p>
                <p class="hot-item-title" v-if="item.type===1 || item.type===4 " @click.stop="handleChangeLinkOrProd(currentEditIndex, index, item.type)">{{ item.title }}</p>
              </div>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item v-for="(linkItem,linkIndex) in linkList"
                                  :key="linkIndex"
                                  :command="({linkItem,currentHotEditIndex:index,isCacheImage:true})">
                  <span style="font-size: 12px;">{{ linkItem.title }}</span>
                </el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
            <i class="el-icon-close close-icon"
               @click="cacheImageActiveBox.splice(index, 1)" />
          </div>
        </div>
      </div>
      <div slot="footer"
           style="text-align: right;margin-top: 20px;">
        <el-button size="mini"
                   type="primary"
                   @click="addHotArea">{{$t('shopFeature.imageAd.addHotArea')}}</el-button>
        <el-button size="mini"
                   @click="saveHotBox">{{$t('shopFeature.imageAd.save')}}</el-button>
      </div>
    </el-dialog>
    <!-- 弹窗, 新增图片 -->
    <elx-imgbox ref="elxImgbox"
                @refreshPic="refreshPic"
                :maxSize="10"
                :imgSizeLimit="false"></elx-imgbox>
    <!-- 商品选择弹窗  -->
    <prods-select v-if="dialogChooseGoods"
                  ref="ProdsSelect"
                  :isSingle="true"
                  @refreshSelectProds="chooseGoodsFun"></prods-select>
    <!--选择微页面-->
    <el-dialog custom-class="up-dialog"
               :close-on-click-modal="false"
               top="5vh"
               :title="$i18n.t('shopFeature.tabNav.microPage')"
               :visible.sync="dialogChoosePages"
               width="42%">
      <div class="choose-goods-compent">
        <choose-feature :isGetChooseData="isGetChooseFeature"
                        @chooseChooseFeaturesFun="chooseChooseFeaturesFun"></choose-feature>
        <div slot="footer"
             style="text-align: right;margin-top: 20px;">
          <el-button size="mini"
                     type="primary"
                     @click="isGetChooseFeature=!isGetChooseFeature">{{$t('shopFeature.tabNav.confirm')}}</el-button>
          <el-button size="mini"
                     @click="dialogChoosePages = false">{{$t('shopFeature.tabNav.cancel')}}</el-button>
        </div>
      </div>
    </el-dialog>
    <!-- 弹窗: 输入自定义路径 -->
    <el-dialog custom-class="up-dialog" :title="$i18n.t('shopFeature.tabNav.customPath')" width="40%" top="30vh" :visible.sync="showPathInputDialog">
      <div class="custom-path-con">
        <span>{{$t('shopFeature.tabNav.routeLink')}}</span>
        <el-input style="margin-rigth: 10px;" :placeholder="$i18n.t('shopFeature.tabNav.pleaseFillThePath')" size="small" v-model="customPath">

        </el-input>
      </div>
      <div slot="footer" style="text-align: right;">
          <el-button size="mini"
                     type="primary"
                     @click="customPathComfirm">{{$t('shopFeature.tabNav.confirm')}}</el-button>
          <el-button size="mini"
                     @click="customPathCancel">{{$t('shopFeature.tabNav.cancel')}}</el-button>
        </div>
    </el-dialog>
  </div>
</template>
<script>
import index from './index.js'

export default index
</script>
